# include <stdio.h>
# include <conio.h>
# include <iostream.h>
main()
{
int x=0,j,n,y=0,i,jum=0,bt[100],at[100],p[100],nama[100],w=0,m,z[100],max=0;

float hsl;
cout <<"__________________Program Penjadwalan FIFO (First In First Out)_________________";cout<<endl;
cout<<endl;
cout<<endl;
cout<<"<A> Daftar Nama Kelompok :"; cout<<endl;
cout<<"    1. Farhan Abianto (1310511085)";cout<<endl;
cout<<"    2. Muchtar Saputra (1310511080)";cout<<endl;
cout<<"    3. Denyy Dwi Kristanto (1310511063)";cout<<endl;
cout<<"    4. Helda Novianto (1310511066)";cout<<endl;
cout<<endl;			
cout<<"<B> Mata Kuliah : Sistem Operasi ";
cout<<endl;
cout<<endl;
printf("<C> Dosen : Bpk. Arya Adhyaksa Waskita,S.Si, M.Si ");
cout<<endl;
cout<<endl;
cout<<"<D> Tujuan : Membuat Tugas Program Penjadwalan FIFO Dengan Bahasa C++";
cout<<endl;
cout<<endl;
cout<<endl;
cout<<">>>>>>>>>>Proses Penjadwalan<<<<<<<<<<";
cout<<endl;
cout<<endl;
cout<<"<1> Masukkan Jumlah Proses : ";
cin>>n, "%d";
cout<<endl;


cout<<endl;
for(i=0;i<n;i++)
{
cout<<"<2> Masukkan Nilai Burst Time P"<<i+1, "%s";
cout<<" : ";
cin>>bt[i], "%d";
}
cout<<endl;
cout<<"<3> Masukkan Nilai Arrival Time P1 : 0"<<endl;
at[0]=0,nama[0]=1;
for(i=1;i<n;i++)
{
cout<<"<3> Masukkan Nilai Arrival Time P"<<i+1<<" : ";
cin>>at[i];nama[i]=i+1;
}
int temp;
for(i=0;i<n;i++){
		
	for(j=0;j<n;j++){
	if(at[i]<at[j]){
		temp=at[j];
		at[j]=at[i];
		at[i]=temp;
		
		temp=nama[j];
		nama[j]=nama[i];
		nama[i]=temp;

		temp=bt[j];
		bt[j]=bt[i];
		bt[i]=temp;
	}
	}
}
cout<<endl;
cout<<"-----------------------------------------------";
cout<<endl;
cout<<"|   Nama  |  Burst time  |    Arrival Time   |";
cout<<endl;
cout<<"-----------------------------------------------";
cout<<endl;
for(i=0;i<n;i++)
{
cout<<"    P"<<nama[i], "%s";
cout<<"           "<<bt[i],	"%d";
cout<<"                "<<at[i], "%d";
cout<<endl; 	
}
cout<<endl;
cout<<"----------------------------";
cout<<endl;
cout<<endl;
cout<<">>>>>>>Diagram Grant<<<<<<<<";
cout<<endl;
cout<<endl;
for(i=0;i<n;i++)
{
cout<<"------------------------------------------";
cout<<endl;
cout<<"Penjadwalan proses "<<nama[i], "%s"; 
cout<<" Dari "<<x, "%d";
cout<<" (Waktu Tunggu)";
cout<<" Ke "<<(x+bt[i]), "%d";
cout<<endl;
cout<<"------------------------------------------";
x=x+bt[i];
z[i]=x;
max=max+z[i];
cout<<endl;
}
int k;
k=at[0];
for(i=0;i<(n-1);i++)
{
	k=k+z[i]-at[i+1];
}
hsl=(float)k/n;
cout<<endl;
cout<<"<4> Average Waiting Time : "<<hsl;

cout<<endl;
cout<<endl;
float ta;
ta=(float)max/n;
cout<<"<5> Turn Around Time : "<<ta;
cout<<endl;
getch();
}
